package controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import service.UserService;
import entity.User;
@Controller
@RequestMapping("/user/")
public class UserController  {
	@Resource
	private UserService usi;
	@RequestMapping("login.html")
	public String login(){
		return "login";
	}
	@RequestMapping(value="login")
	public String login(User user,Model model,HttpSession session){
		user=usi.getUser(user);
		if(user==null){
			model.addAttribute("meg", "用户名或密码错误");
			return "login";
		}
		model.addAttribute(user);
		session.setAttribute("username", user.getUname());
		return "main";
	}
	@RequestMapping(value="exit")
	public String exit(HttpSession session){
		session.invalidate();
		return "login";
	}
}
